﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Business;
using ThoiTrang.Entities; 

public partial class login : System.Web.UI.Page
{
    public bool error = true;
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "Thoitrang.com-dang nhap";
        if (IsPostBack)
        {
            error = true;
            //Page.Title = "Thoitrang.com-dang nhap";
            a_User usr = a_UserService.Geta_UserByEmail(Request["email_dangnhap"]);
            
            if (usr != null)
            {
            
                if (usr.Password != Request["matma"])
                {
                    InfoError.InnerHtml = "Sai mật khẩu. Đăng nhập thất bại!";
                }
                else
                {
                    a_Session ss = a_SessionService.Geta_Session(SessionManager.GetCookie());
                    if (ss != null)
                    {
                        ss.CookieID = usr.CookieID;
                        ss.Login_Status = true;
                        a_SessionService.Updatea_Session(ss);
                    }
                    //InfoError.InnerHtml = "Đăng nhập thành công!";
                    if(usr.UserTypeID == 1)
                        Response.Redirect("Admin/adm_article_list.aspx?st=0&ckid=" + SessionManager.GetCookie());
                    else
                        Response.Redirect("user_index.aspx?t=t&ckid=" + SessionManager.GetCookie());
                }
            }
            else
            {
                InfoError.InnerHtml = "Sai email. Đăng nhập thất bại!";
            }
        }
        else
        {
            Form.Attributes.Add("onsubmit", "return CheckFormLogin(this);");
            Form.Method = "post";
        }
    }
}
